﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SpeakOut.Lib;

namespace SpeakOut.Model
{
    public class Author
    {

        public virtual Guid AuthorId { get; set; }

        public virtual string Name { get; set; }

        public virtual string Login { get; set; }

        public virtual string Password { get; set; }

        public virtual string Email { get; set; }

        public virtual bool IsAdmin { get; set; }

        private IList<Post> _posts;
        public virtual IEnumerable<Post> Posts
        {
            get { return _posts; }
        }

        public Author()
        {
            AuthorId = Guid.Empty;
            _posts = new List<Post>();
        }

        public virtual void AddPost(Post post)
        {
            post.Author = this;
            _posts.Add(post);
        }

        private bool Equals(Author other)
        {
            if (ReferenceEquals(null, other)) return false;
            if (ReferenceEquals(this, other)) return true;
            return other.AuthorId.Equals(AuthorId);
        }

        public override bool Equals(object obj)
        {
            if (ReferenceEquals(null, obj)) return false;
            if (ReferenceEquals(this, obj)) return true;
            if (obj.GetType() != typeof(Author)) return false;
            return Equals((Author)obj);
        }

        public override int GetHashCode()
        {
            return AuthorId.GetHashCode();
        }
    }
}
